package com.aegean.MonitorExamSYS.examinee.action;

import javax.annotation.Resource;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.examinee.business.ExamineeBusiness;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("UserUpdateLocation")
@Scope("prototype")
public class UserUpdateLocation extends ActionSupport {
	@Resource
	ExamineeBusiness business;
	private ExamineeValue user;
	private float lat;
	private float lng;
	private String address;
	private String route;
	private String city;
	private String region;
	private boolean success;
	private String msg;

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getRoute() {
		return route;
	}

	public void setRoute(String route) {
		this.route = route;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getRegion() {
		return region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public float getLat() {
		return lat;
	}

	public void setLat(float lat) {
		this.lat = lat;
	}

	public float getLng() {
		return lng;
	}

	public void setLng(float lng) {
		this.lng = lng;
	}

	@Override
	public String execute() {
		// TODO Auto-generated method stub
		user = (ExamineeValue) ServletActionContext.getRequest().getSession()
				.getAttribute("UserLogin");
		try {
			user = business.updateUserLocation(user, lat, lng, address,
					route, city, region);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		if (user != null) {
			ServletActionContext.getRequest().getSession()
					.setAttribute("UserLogin", user);
			msg = "恭喜你，修改成功！";
			success = true;
		} else {
			msg = "对不起，犹豫故障您不能修改定位，请您登陆后选择移动定位重新定位！";
			success = false;
		}
		return SUCCESS;
	}

}
